import com.google.gson.Gson;
import model.Translation;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.junit.Test;

import java.io.*;

public class testHttp {
    @Test
    public void test() {
        String baseUrl = "http://fanyi.youdao.com/openapi.do?keyfrom=Skykai521&key=977124034&type=data&doctype=json&version=1.1&q=";

        OkHttpClient okHttpClient = new OkHttpClient();

        final Request request = new Request.Builder()
                .url(baseUrl + "quals,\\\"40\\\")){")
                .get()
                .build();
        Call call = okHttpClient.newCall(request);
        try {
            String string = call.execute().body().string();
            Translation translation = new Gson().fromJson(string, Translation.class);
            // 展示出来
            System.out.println(string);
            System.out.println(translation);
            System.out.println(string.substring(string.indexOf("errorCode") + 11, string.indexOf("errorCode") + 12));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testError() throws FileNotFoundException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(
                        new FileInputStream("")));

    }
}
